package com.gtr.controller;


import com.gtr.entity.VaccinumInfo;
import com.gtr.service.VaccinumCategoryService;
import com.gtr.service.VaccinumInfoService;
import com.gtr.util.ResultVOUtil;
import com.gtr.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.math.BigDecimal;

/**
 * <p>
 * 类目表 前端控制器
 * </p>
 *
 * @author gtr
 * @since 2023-02-22
 */
@RestController
@RequestMapping("/buyer/vaccinum")
public class BuyerVaccinumController {
    @Autowired
    private VaccinumCategoryService vaccinumCategoryService;
    @Autowired
    private VaccinumInfoService vaccinumInfoService;

    @GetMapping("/list") //疫苗列表
    public ResultVO list(){
//        ResultVO resultVO = new ResultVO();
//        resultVO.setCode(0);
//        resultVO.setMsg("成功");
//        resultVO.setData(this.vaccinumCategoryService.buyerList());
//        return resultVO;
        return ResultVOUtil.success(this.vaccinumCategoryService.buyerList());
    }

    @GetMapping("/findPriceById/{id}") //通过id查价格
    public BigDecimal findPriceById(@PathVariable("id") Integer id){
        return this.vaccinumInfoService.findPriceById(id);
    }

    @GetMapping("/findById/{id}") //查疫苗
    public VaccinumInfo findById(@PathVariable("id") Integer id) {
        return this.vaccinumInfoService.getById(id);
    }

    @PutMapping("/subStockById/{id}/{quantity}") //减少库存
    public Boolean subStockById(@PathVariable("id") Integer id, @PathVariable("quantity") Integer quantity) {
        return this.vaccinumInfoService.subStockById(id, quantity);
    }

    @PutMapping("/addStockById/{id}/{quantity}") //加库存
    public Boolean addStockById(
            @PathVariable("id") Integer id
            ,@PathVariable("quantity") Integer quantity){
        return this.vaccinumInfoService.addStock(id, quantity);
    }

}

